Skip thread-name lookup for outputs that do not use names - #862
Open
jonashaag wants to merge 1 commit into
Open
Conversation
jonashaag
marked this pull request as ready for review
July 17, 2026 10:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Full disclosure: This has been written by GPT 5.6 Sol.
It is a symptom-treat for #855 (comment) that I consider generally useful.
Summary
dump, speedscope, and every recording using--threadsConfigMotivation
Thread names are resolved by walking the target process's
sys.modulesand thethreadingmodule's_activedictionary. This work does not contribute to several outputs:topdoes not display individual thread names--threadsadds a synthetic thread frame--threadsAvoiding the lookup matters especially when it fails: the name cache remains empty and py-spy retries the remote dictionary walk for every sampled thread on every sample. This change makes the collection decision before
PythonSpy::retry_new, so even the validation sample avoids unused lookup work.Speedscope continues collecting names because it uses them as profile labels.
dumpand directPythonSpyusers retain the existing behavior by default.This PR is independent of #861 and applies directly to
master.Validation
--threadspre-commit run --all-filescargo test --releasewith Python 3.13cargo test --libcargo check --all-targetscargo check --lib --no-default-features